import 'package:demo_echarts/hua.dart';
import 'package:flutter/material.dart';
import 'package:flutter_echarts/flutter_echarts.dart';


void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  //定义key,不知道能否有用
  @override
  void initState() {
    super.initState();
  }
  //定义变量，方便动态使用
  String xAxis = 'xAxis';
  String type = 'type';
  String data = 'data';
  String yAxis = 'yAxis';
  String series = 'series';


  @override
  Widget build(BuildContext context) {

    var option1 ='''
    {
      tooltip: {
        trigger: 'axis',
      },
      legend: {
        data: ['W1','W2','P1','P2']
      },
      xAxis: {
        type:'category',
        data:['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
      },
      yAxis:[
          {
            show:true,
            type:'value',
            axisLine:{
              onZero:false,
              lineStyle:{
                color:'#666'
              }
            },
            position:'left',
            name:'温度',
            nameLocation:'end',
            nameTextStyle:{
              color:'#306090'
            }
          },
         {
           show:'true',
           type:'value',
           axisLine:{
           onZero:false,
           },
           name:'压强',
           position:'right',
           nameLocation:'end'
         }
        ],
      series:[
        {
          name: 'W1',
          data:[820,932,901,934,1290,1330,1320],
          type:'line',
          yAxisIndex:0,
          symbol:'none',
           smooth: 0.4,
          itemStyle:{
            normal:{
              color:'red'
            }
          }
        },
        {
          name: 'W2',
          data:[369,248,147,369,985,211,689],
          type:'line',
          yAxisIndex:0,
          symbol:'none',
           smooth: 0.4,
          itemStyle:{
            normal:{
              color:'blue'
            }
          }
        },
         {
           name:'P1',
           data:[10,20,30,40,55,88,77,],
           type:'line',
           yAxisIndex:1,
           symbol:'none',
           smooth: 0.4,
         },
         {
           name:'P2',
           data:[120,208,55,88,309,188,277,],
           type:'line',
           yAxisIndex:1,
           symbol:'none',
           smooth: 0.4,
         }
      ]
    }''';
    var option2 = '''{
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      },
      yAxis: {
        type: 'value'
      },
      series: [{
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line'
      }]
    }''';
    String option = option2.toString();
    //绘制多条曲线在series中添加。
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(

        title: Column(children: [
          Text('蒸气发生器'),
          Text('报表',style: TextStyle(fontSize: 12),)
        ],),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        child: Center(
          child: Column(
            children: [
              Container(
                child: Echarts(
                  option: option1,
                ),
                width: 300,
                height: 200,
              ),
              TextButton(onPressed: (){
                setState(() {
                  Navigator.push(context, MaterialPageRoute(builder: (context){return Hua();}));
                });
              }, child: Text('下一页'))
            ],),
        ),
            ),
    );
  }
}
